<?php
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
//$incldue_tmp = base_url() . "application/views/fpdf/fpdf.inc";
//require ($incldue_tmp);//including the main class
	
	$pdf = new FPDF();
	$pdf->AddPage();
	$pdf->SetFont('Arial', 'B', 12);
	
	$pdf->SetX(5);
	$pdf->SetY(5);
	/*Header*/
	$pdf->Cell(190,10, $_REQUEST['kind'] ,"TB",0,'C');
	
	$pdf->SetFont('Arial', 'B', 48);
	$pdf->SetX(5);
	$pdf->SetY(15);
	/*Company Name*/
	$pdf->MultiCell(110,15, $_REQUEST['company_name'] ,0,'L');
	
	$pdf->SetFont('Arial', 'B', 12);
	$pdf->SetX(110);
	$pdf->SetY(45);
	/*Company Info*/
	$pdf->Cell(140,10, "",0,0,'C');
	$pdf->MultiCell(50,10, $_REQUEST['company_info'] ,0,'R');
	
	$pdf->SetX(5);
	$pdf->SetY(65);
	/*Recipient Info*/
	$pdf->MultiCell(80,10, $_REQUEST['recipient_info'] ,0,"L");
	
	$pdf->SetX(5);
	$pdf->SetY(85);
	/*Invoice Info*/
	$pdf->Cell(130,10, "",0,0,'C');
	$pdf->Cell(25,10, $_REQUEST['invoice_number_label'] ,"LTRB",0,'C');
	$pdf->Cell(35,10, $_REQUEST['invoice_number'] ,"LTRB",0,'C');
	
	$pdf->SetX(5);
	$pdf->SetY(95);
	$pdf->Cell(130,10, "",0,0,'C');
	$pdf->Cell(25,10, $_REQUEST['invoice_date_label'] ,"LTRB",0,'C');
	$pdf->Cell(35,10, $_REQUEST['invoice_date'] ,"LTRB",0,'C');
	
	
	
	$pdf->SetFont('Arial', 'B', 12);
	$pdf->SetX(5);
	$pdf->SetY(110);
	/*Table Header->Items*/
	$pdf->Cell(114,10, "Item & Description","LTRB",0,'C');
	$pdf->Cell(23,10, "Rate","LTRB",0,'C');
	$pdf->Cell(30,10, "Quantity","LTRB",0,'C');
	$pdf->Cell(23,10, "Price","LTRB",0,'C');
	
		
			$d_x = 5;
			$d_y = 120;
			$glbl_posy = 0;
	for($i = 0, $l = count($_POST['items_descp']); $i < $l; $i++)
		{	
			$tmp = 10*$i;
			$tmp1 = $d_y + $tmp; 
			$glbl_posy = $tmp1;
			$pdf->SetX(5);
			$pdf->SetY($tmp1);
			
			/*Table Data->Items*/
			$pdf->Cell(114,10, $_REQUEST['items_descp'][$i] ,"LTRB",0,'C');
			$pdf->Cell(23,10, $_REQUEST['items_rate'][$i] ,"LTRB",0,'C');
			$pdf->Cell(30,10, $_REQUEST['items_qty'][$i] ,"LTRB",0,'C');
			$pdf->Cell(23,10, $_REQUEST['items_prc'][$i] ,"LTRB",0,'C');
		
		}
		
		$tmp2 = $glbl_posy + 20;
		
	$pdf->SetX(130);
	$pdf->SetY($tmp2);
	$tax_perc =	$_REQUEST['tax_percentage'] . "%";
	/*Table Header->Summary*/
	$pdf->Cell(130,10,"",0,0,'C');
	$pdf->Cell(23,10, $_REQUEST['subtotal_label'] ,"LTRB",0,'C');
	$pdf->Cell(14,10, " " ,"LTRB",0,'C');
	$pdf->Cell(23,10, $_REQUEST['subtotal'] ,"LTRB",0,'C');
	
	$tmp2 = $tmp2 + 10;
	$pdf->SetX(130);
	$pdf->SetY($tmp2);
	
	$pdf->Cell(130,10,"",0,0,'C');
	$pdf->Cell(23,10, $_REQUEST['tax_name'] ,"LTRB",0,'C');
	$pdf->Cell(14,10, $tax_perc ,"LTRB",0,'C');
	$pdf->Cell(23,10, $_REQUEST['tax_amount'] ,"LTRB",0,'C');
	
	$tmp2 = $tmp2 + 10;
	$pdf->SetX(130);
	$pdf->SetY($tmp2);
	
	$pdf->Cell(130,10,"",0,0,'C');
	$pdf->Cell(23,10, $_REQUEST['total_label'] ,"LTRB",0,'C');
	$pdf->Cell(14,10, $_REQUEST['currency_symbol'] ,"LTB",0,'R');
	$pdf->Cell(23,10, $_REQUEST['total'] ,"TRB",0,'L');
	
	//Test
	//$pdf->SetX(130);
	//$pdf->SetY(200);
	//$pdf->Cell(23,10, "Test" ,"LTRB",0,'C');
	
	/*Note "A" Note "B"*/
	$pdf->SetX(5);
	$pdf->SetY(266);
	$pdf->Cell(95,10, $_REQUEST['notes_a'] ,"T",0,'L');
	$pdf->Cell(95,10, $_REQUEST['notes_b'] ,"T",0,'R');
	
	$pdf->Output('invoice.pdf', 'D');
	
	
?>	